package com.example.desksginktapp.wigit;

import android.app.AlertDialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.desksginktapp.R;

public class IosStyleDialog {
    private AlertDialog dialog;
    private Context context;
    private View dialogView;

    private TextView tvCheckInTime;
    private TextView tvCheckOutTime;
    private TextView tvTitle;
    private Button btnConfirm;

    public IosStyleDialog(Context context) {
        this.context = context;
        initDialog();
    }

    private void initDialog() {
        AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.IosDialogStyle);
        dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_ios_style, null);

        tvTitle = dialogView.findViewById(R.id.dialog_title);
        tvCheckInTime = dialogView.findViewById(R.id.checkInTime);
        tvCheckOutTime = dialogView.findViewById(R.id.checkOutTime);
        btnConfirm = dialogView.findViewById(R.id.btn_confirm);

        builder.setView(dialogView);
        dialog = builder.create();

        // 设置点击外部不可取消
        dialog.setCanceledOnTouchOutside(false);

        btnConfirm.setOnClickListener(v -> dismiss());
    }

    public IosStyleDialog setTitle(String title) {
        tvTitle.setText(title);
        return this;
    }

    public IosStyleDialog setCheckInTime(String time) {
        tvCheckInTime.setText(time);
        return this;
    }

    public IosStyleDialog setCheckOutTime(String time) {
        tvCheckOutTime.setText(time);
        return this;
    }

    public IosStyleDialog setCancelable(boolean cancelable) {
        if (dialog != null) {
            dialog.setCancelable(cancelable);
        }
        return this;
    }

    public void show() {
        if (dialog != null && !dialog.isShowing()) {
            dialog.show();
        }
    }

    public void dismiss() {
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
        }
    }

    public boolean isShowing() {
        return dialog != null && dialog.isShowing();
    }
}
